<template>
    <div class="index clearafter">
        <module-head></module-head>
        <div class="content flex">
            <div class="w220">
                <menu-list></menu-list>
            </div>
            <div class="w980 flex_full">
                <div class="flex flex_between">
                  <p class="flex flex_vcenter pdb20">
                    <i class="titleTag"></i>
                    <span class="fRedBig">模块管理</span>
                  </p>
                    <button class="longBtn" @click="editmodule()">新增模块</button>
                    <div id="searchbyname">
                        <div class="col-md-6">
                            <input type="text" class="form-control" v-model="param.content" placeholder="模块名称或编码">
                        </div>
                        <div class="col-md-3">
                            <button class="default blue" @click="searchbyinput">搜索</button>
                        </div>
                    </div>
                </div>
                <div class="servicepeoplelist bg">
                    <table class="table table-hover table-striped">
                        <thead>
                            <tr>
                                <th>模块编码</th>
                                <th>模块名称</th>
                                <th>链接URL</th>
                                <th>连接类型</th>
                                <th>排序</th>
                                <th>备注</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr v-for="item in modulelists" track-by="$index">
                                <td>{{item.moduleCode}}</td>
                                <td>{{item.moduleName}}</td>
                                <td>{{item.linkedUrl}}</td>
                                <td>{{item.linkedTypeText}}</td>
                                <td>{{item.moduleOrder}}</td>
                                <td>{{item.moduleDesc}}</td>
                                <td><span class="glyphicon glyphicon-pencil" @click="editmodule(item)"></span><span class="glyphicon glyphicon-trash" @click="delemodule(item)"></span></td>
                            </tr>
                            <tr>
                                <td colspan="7">
                                    <div class="pull-left">
                                        <button class="secondBtn" @click="refresh">刷新</button>
                                    </div>
                                    <div class="pull-right">
                                        <!-- 分页组件: -->
                                        <boot-page v-ref:page :async="true" :lens="lenArr" :page-len="pageLen" :headersparam="headersparam" :param="param"></boot-page>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="modal fade bs-example-modal-lg" id="editmodule" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">{{edittit}}</h4>
                    </div>
                    <form class="form-horizontal cb" role="form" id="selectmodule" v-on:submit.prevent="savemodule">
                        <div class="modal-body">
                            <div class="menuset_con menuset_con2">
                                <div class="menuset_con_right fl">
                                    <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="start">*</span>模块名称:</label>
                                        <div class="col-md-8">
                                            <input type="text" class="form-control" required v-model="savedata.module.moduleName" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="start">*</span>模块编码:</label>
                                        <div class="col-md-8">
                                            <input type="text" class="form-control" required v-model="savedata.module.moduleCode" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="start">*</span>链接类型:</label>
                                        <div class="col-md-8">
                                            <select class="form-control" required v-model="savedata.module.linkedType">
                                                <option :value="item.key" v-for="(index,item) in linktypelists">{{item.text}}</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="start" v-show="savedata.module.linkedType!='00'">*</span>链接URL:</label>
                                        <div class="col-md-8">
                                            <input type="text" class="form-control" :required="savedata.module.linkedType!='00'" v-model="savedata.module.linkedUrl" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">排序:</label>
                                        <div class="col-md-8">
                                            <input type="text" class="form-control" v-model="savedata.module.moduleOrder" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">备注说明:</label>
                                        <div class="col-md-8">
                                            <textarea class="form-control" rows="3" v-model="savedata.module.moduleDesc"></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="menuset_con_left  fr">
                                    <h3>模块权限</h3>
                                    <div class="treecon">
                                        <label class="checkbox-inline" v-for="(index,item) in actionInfolists">
                                            <input type="checkbox" value="{{item.actionValue}}" v-model="savedata.actionValueList" name="actionInfo"> {{item.actionName}}
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer savebtn">
                            <button type="submit" class="default ok center">确认</button>
                        </div>
                    </form>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- 删除模块 -->
        <div class="modal fade" id="delemodule" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body cbafter">
                        <p class="text-center">确认删除模块：<span class="red">{{currentmodule.moduleName}}？</span></p>
                    </div>
                    <div class="modal-footer">
                        <div class="centerbutton">
                            <button @click="confirmdelemodule" class="default cancel center">确认删除</button>
                            <button type="button" class="default greynobg center " data-dismiss="modal" aria-hidden="true">取消</button>
                        </div>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal -->
        </div>
    </div>

</template>
<script>
import 'assets/lib/bootstrap-3.3.2/css/bootstrap.min.css'
import 'assets/lib/bootstrap-3.3.2/js/bootstrap.min.js'
import 'assets/reset.css'
import Public from 'assets/public.js'
import moduleHead from 'components/module-head'
import menuList from 'components/menu-list'
import bootPage from 'components/BootPage.vue'
export default {
    data() {
            return {
                lenArr: [10, 20, 50], // 每页显示长度设置
                pageLen: 5, // 可显示的分页数
                headersparam: {
                    "X-Service-Id": "base.moduleService",
                    "X-Service-Method": "queryModule",
                },
                param: {
                    content: ""
                },
                modulelists: [],
                searchinput: "",
                savedata: {
                    "actionValueList": [],
                    "module": {
                        "linkedType": "",
                        "linkedUrl": "",
                        "moduleCode": "",
                        "moduleDesc": "",
                        "moduleId": 0,
                        "moduleName": "",
                        "moduleOrder": ""
                    }
                },
                actionInfolists: [],
                linktypelists: [],
                edittit: "",
                currentmodule: {
                    "linkedType": "",
                    "linkedUrl": "",
                    "moduleCode": "",
                    "moduleDesc": "",
                    "moduleId": 0,
                    "moduleName": "",
                    "moduleOrder": ""
                }
            }
        },
        computed: {},
        components: {
            moduleHead, menuList, bootPage
        },
        ready() {
            var that = this;
            // 获取模块所有模块权限
            $.when(Public.commonajax("base.moduleService", "queryActionInfo", "[[]]"))
                .done(function(res) {
                    if (res.code == 200) {
                        that.actionInfolists = res.body;
                    }
                })
                // 连接类型，字典
            $.when(Public.commonajax("coms.multipleDictionaryService", "findDic", "[['base.dictionary.base_hyperLink']]"))
                .done(function(res) {
                    if (res.code == 200) {
                        that.linktypelists = res.body[0].items;
                    }
                })

        },
        methods: {
            // 列表页面刷新按钮
            refresh() {
                    this.$refs.page.refresh()
                },
                //搜索
                searchbyinput() {
                    this.refresh();
                },
                //新增或修改弹框
                editmodule(item) {
                    var that = this;
                    $("#editmodule").modal("show")
                    if (item) { //修改
                        this.edittit = "修改模块";
                        $.when(Public.commonajax("base.moduleService", "getModuleInfo", "['" + item.moduleId + "']"))
                            .done(function(res) {
                                if (res.code == 200) {
                                     var temarr = [];
                                    if (res.body.moduleActionInfo && res.body.moduleActionInfo.length > 0) {

                                        $.each(res.body.moduleActionInfo, function(index, el) {
                                            temarr.push("" + el.actionValue);
                                        });
                                    };
                                    that.savedata.module = res.body;
                                    that.savedata.actionValueList = temarr;
                                    delete that.savedata.module.moduleActionInfo;
                                    console.log(that.savedata.actionValueList);
                                }
                            })

                    } else { //新增
                        this.edittit = "新增模块";
                        that.savedata = {
                            "actionValueList": [],
                            "module": {
                                "linkedType": "",
                                "linkedUrl": "",
                                "moduleCode": "",
                                "moduleDesc": "",
                                "moduleId": 0,
                                "moduleName": "",
                                "moduleOrder": ""
                            }
                        };

                    }
                },
                //保存新增或修改
                savemodule() {
                    var that=this;
                    $.when(Public.commonajax("base.moduleService", "saveModule", "[" + JSON.stringify(this.savedata) + "]"))
                        .done(function(res) {
                            if (res.code == 200) {
                                Public.ajaxPrompt("保存成功");
                                that.refresh();
                                 $("#editmodule").modal("hide");
                            } else {
                                Public.ajaxPrompt(res.msg)
                            }
                        })
                },
                // 删除模块弹框
                delemodule(item) {
                    var that = this;
                    $("#delemodule").modal("show");
                    this.currentmodule = item;
                },
                //确认删除
                confirmdelemodule() {
                    var that = this;
                    $.when(Public.commonajax("base.moduleService", "deleteModule", "['" + this.currentmodule.moduleId + "']"))
                        .done(function(res) {
                            if (res.code == 200) {
                                Public.ajaxPrompt("删除成功");
                                $("#delemodule").modal("hide");
                                 that.refresh();
                            } else {
                                Public.ajaxPrompt(res.msg);
                            }

                        })
                },


        },
        events: {
            // 分页列表数据
            'data' (data) {
                this.modulelists = data;
            },


        },
        watch: {


        },
}
</script>
<style scoped>
.servicepeoplelist {
    padding: 20px
}

.servicepeoplelist table th {
    text-align: center;
    line-height: 36px;
    height: 36px;
    font-weight: normal;
}

.servicepeoplelist table td {
    line-height: 40px;
    text-align: center;
    color: #898989;
}

.servicepeoplelist table tr td:nth-child(1) {
    font-weight: bold;
    color: #333;
    text-align: left;
    width: 80px
}

.servicepeoplelist table tr td:nth-child(2),
.servicepeoplelist table tr td:nth-child(3) {
    color: #333
}

.servicepeoplelist table tr td:nth-child(4) {
    width: 80px
}

.servicepeoplelist table tr td:nth-child(5) {
    width: 60px
}

.servicepeoplelist table tr td:nth-child(6) {
    width: 150px
}

.servicepeoplelist table tr td:nth-child(7) {
    width: 80px
}

.servicepeoplelist table tr td .glyphicon {
    display: inline-block;
    width: 30px;
    height: 30px;
}

.servicepeoplelist table tr td .glyphicon:hover {
    color: #1dc499;
    cursor: pointer;
}

.menuset_con {
    width: 950px;
    min-height: 644px;
    height: auto!important;
    border: 1px solid #e6e6e6;
    border-radius: 10px;
    padding-top: 30px;
    background-color: #fafafa;
}

.menuset_con_left {
    border-radius: 0 0 10px 0;
    overflow: auto;
    border-radius: 5px;
    width: 250px
}

.menuset_con_right {
    width: 570px;
    border-right: 1px #ccc solid
}

.menudetailform,
.treecon {
    border: 1px solid #ccc;
    padding: 20px 10px;
    border-radius: 5px;
    min-height: 274px;
}

.menuset_con2 {
    width: 100%;
    min-height: 400px;
    height: auto!important;
    border: none;
    border-radius: 0;
    padding-top: 30px;
    background-color: #fff;
}

.menuset_con2 .menuset_con_left {}

.menuset_con2 .menuset_con_left h3 {
    font-size: 16px;
    line-height: 40px;
    font-weight: bold;
}

.menuset_con2 .menuset_con_left input {
    padding: 10px;
}

.menuset_con2 .menuset_con_left ul li {
    line-height: 30px;
    height: 30px;
    width: 100px;
    margin: 0 auto;
}

.menuset_con2 .menuset_con_left ul li.active {
    background: #1dc499;
    border-radius: 15px;
    color: #fff
}

.menuset_con2 .menuset_con_right table th {
    background: #1dc499;
    color: #fff
}

.treecon .checkbox-inline:first-child {
    margin-left: 10px
}

.checkbox-inline {
    width: 100px
}

.centerbutton {
    width: 280px;
    margin: 0 auto;
}

.centerbutton button {
    margin-left: 5px;
    display: inline-block;
}
span.red {
    font-weight: bold;
    color: #f86448
}
</style>
